﻿using AutoMapper;
using System;
using LanhuFx.Services.Model.View;
using LanhuFx.Services.Model.Dto;
using LanhuFx.Context.PgSql.ResourcesModels;
using LanhuFx.Identity;

namespace LanhuFx.Services
{
    public class AutoMapperProfileConfiguration : Profile
    {
        public AutoMapperProfileConfiguration()
        {
            CreateMap<IdentityRole, View_Role>();

            CreateMap<DtoPermissionSetting, IdentityUserpermissions>()
                .ForMember(c => c.Id, x => x.MapFrom(c => Guid.NewGuid()))
                .ForMember(c => c.Createat, n => n.MapFrom(c => DateTime.Now));

            CreateMap<IdentityRolepermissions, View_UserPermission>()
                .ForMember(c => c.Name, x => x.MapFrom(c => c.Promission.Name))
                .ForMember(c => c.Id, x => x.MapFrom(c => c.Promission.Id))
                .ForMember(c => c.PermissionType, x => x.MapFrom(c => c.Permissiontype));

            CreateMap<View_PermissionUser, View_UserPermission>()
                .ForMember(c => c.Name, x => x.MapFrom(c => c.Name))
                .ForMember(c => c.Id, x => x.MapFrom(c => c.Id))
                .ForMember(c => c.PermissionType, x => x.MapFrom(c => c.PermissionType));

            CreateMap<Dto_CreateRole, IdentityRole>()
                .ForMember(c => c.Id, x => x.MapFrom(c => Guid.NewGuid()))
                .ForMember(c => c.Issystem, x => x.MapFrom(c => false));

            CreateMap<IdentityPermissionsetting, View_PermissionUser>()
                .ForMember(c => c.PermissionType, x => x.MapFrom(c => 0))
                .ForMember(c => c.PermissionType_Setting, x => x.MapFrom(c => c.Permissiontype))
                .ForMember(c => c.IsProhibit, x => x.MapFrom(c => false));

        }
    }
}
